<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyle.html">
</head>
<body>
<div style=" overflow-y: auto;height: 583px;">
    <fieldset style="margin: 5px 2px 5px 2px;" zone="team" >
        <legend><span>规则设置</span></legend>
        <div class="table-top">
            <div class="table-top-right" style="float: right">
                <div class="layui-btn-container" >
                    <a class="layui-btn layui-btn-sm" id="addRule" data-method="addRule">添加规则</a>
                    <a class="layui-btn layui-btn-sm" id="addDivf">添加脚本</a>

                    <!--<a class="layui-btn layui-btn-sm" >组合规则</a>-->
                    <!--<a class="layui-btn layui-btn-sm" >拆分规则</a>-->

                    <a class="layui-btn layui-btn-danger layui-btn-sm" id="theDelRules">删除</a>
                </div>
            </div>
            <div style="clear: both"></div>
        </div>
        <div id="ruleDiv" style="border:2px solid #ccc;margin:5px 0 0 0;"></div>
    </fieldset>
    <fieldset style="margin: 5px 2px 5px 2px;" zone="team" >
        <legend><span>人员设置</span></legend>
        <div class="table-top-right">
            <div class="layui-btn-container" style="float: right">
                <a class="layui-btn layui-btn-sm" id="addUser">添加</a>
                <a class="layui-btn layui-btn-danger layui-btn-sm" id="delUser">删除</a>
                <a class="layui-btn layui-btn-sm" id="userLook">预览</a>
            </div>
            <div style="clear: both"></div>
            <div>
                <table style="width:100%;text-align: center;" id="userTable" class="layui-table" >
                    <thead>
                    <tr >
                        <th width="40" style="text-align: center" nowrap="nowrap">序号</th>
                        <th width="20%" style="text-align: center" nowrap="nowrap">用户类型</th>
                        <th width="*" style="text-align: center" nowrap="nowrap">用户来自</th>
                        <th width="15%" style="text-align: center" nowrap="nowrap">抽取用户</th>
                        <th width="*" style="text-align: center" nowrap="nowrap">排序</th>
                        <th nowrap="nowrap" width="80" style="text-align: center">运算类型</th>
                    </tr>
                    </thead>
                    <tbody id="tbodyUserSet">
                    <#list userList as list>
                    <tr>
                        <td nowrap="nowrap" height="28">
                            <input type='checkbox' name='nodeUserCk'/>
                            <input type="hidden" name="modelId" value="${modelId}"/>
                            <input type="hidden" name="procDefId" value="${actDefModel.procDefId}"/>
                            <input type="hidden" name="nodeId" value="${nodeId}"/>
                            <input type="hidden" name="parentProcDefId" value="${parentProcDefId}"/>
                        </td>
                        <td><#--用户类型 -->
                            <input type="hidden" name="nodeUserId" value="${list.nodeUserId}" />
                            <input type="hidden" name="conditionId" value="${list.conditionId}" class="${list.assignType}"/>
                            <select name="assignType" class="userSetSelect" style="width: 80%;height: 38px;border-color: #D2D2D2!important;" lay-verify="required" >
                                <#list assignUserTypes?keys as key>
                                <option value="${key}"            <#if list.assignType== key >selected='selected'</#if>>${assignUserTypes[key].title}</option>
                        </#list>
                        <!--<option value="orgTypeUserLeader" <#if list.assignType=='orgTypeUserLeader' >selected='selected'</#if>  >部门的上级类型部门的负责人</option>-->
                        <!--<option value="startOrPrev"       <#if list.assignType=='startOrPrev' >selected='selected'</#if>  >发起人或上一任务执行人的领导或负责人</option>-->
                        <!--<option value="startOrPrevWithOrg"<#if list.assignType=='startOrPrevWithOrg' >selected='selected'</#if>  >与发起人或上一任务执行人具有相同组织的人</option>-->
                        <!--<option value="approve"           <#if list.assignType=='approve' >selected='selected'</#if>  >当前流程实例审批人</option>-->
                        </select>
                        </td>
                        <td><#--用户来自-->
                            <textarea style="display: none;" name="cmpIds" class="hiddenJson">${list.cmpIds}</textarea>
                            <#if list.assignType=='startUser' >
                            <textarea name="cmpNames" style="display:none;width:73%;min-height: 100px;border-color: #D2D2D2!important;line-height: 20px;vertical-align: bottom;" rows="2" class="textarea" readonly="readonly">${list.cmpNames}</textarea>
                            <a class="windowButton layui-btn layui-btn-sm" style="display:none;" ><span>选择...</span></a>
                            <#elseif  list.assignType=='approve'  >
                            <textarea name="cmpNames" style="display:none;width:73%;min-height: 100px;border-color: #D2D2D2!important;line-height: 20px;vertical-align: bottom;" rows="2" class="textarea" readonly="readonly">${list.cmpNames}</textarea>
                            <a class="windowButton layui-btn layui-btn-sm" style="display:none;" ><span>选择...</span></a>
                            <#else>
                            <textarea name="cmpNames" style="width:73%;min-height: 100px;border-color: #D2D2D2!important;line-height: 20px;vertical-align: bottom;" rows="2" class="textarea" readonly="readonly">${list.cmpNames}</textarea>
                            <a class="windowButton layui-btn layui-btn-sm"  ><span>选择...</span></a>
                        </#if>
                        </td>
                        <td><#--抽取用户-->
                            <select name="extractUser" style="width: 80%;height: 38px;border-color: #D2D2D2!important;">
                                <option value="0" <#if list.extractUser==0>selected="selected"</#if> >不抽取</option>
                            <option value="1" <#if list.extractUser==1>selected="selected"</#if> >抽取</option>
                        </select>
                        </td>
                        <td><#--排序-->
                            <a alt='上移' href='javascript:;' class='link moveup '    onclick="sortTr(this,true)" style="width: 20px;height: 20px;"><i class="iconfont iconlong-arrow-up"></i></a>
                            <a alt='下移' href='javascript:;' class='link movedown '  onclick="sortTr(this,false)" ><i class="iconfont iconlong-arrow-down"></i></a>
                        </td>
                        <td><#--运算关系-->
                            <select name="compType" style="width: 80%;height: 38px;border-color: #D2D2D2!important;">
                                <option value='0' <#if list.compType==0>selected="selected"</#if> >或</option>
                            <option value='1' <#if list.compType==1>selected="selected"</#if> >与</option>
                        <option value='2' <#if list.compType==2>selected="selected"</#if> >排除</option>
                    </select>
                    </td>
                    </tr>
                    </#list>
                    <#if !(userList??  && (userList?size > 0))  >
                    <tr>
                        <td nowrap="nowrap" height="28">
                            <input type='checkbox' name='nodeUserCk'/>
                            <input type="hidden" name="modelId" value="${modelId}"/>
                            <input type="hidden" name="nodeId" value="${nodeId}"/>
                            <input type="hidden" name="parentProcDefId" value="${parentProcDefId}"/>
                        </td>
                        <td><#--用户类型 -->
                            <input type="hidden" name="nodeUserId" value="${list.nodeUserId}" />
                            <input type="hidden" name="conditionId" value="${list.conditionId}" class="${list.assignType}"/>
                            <select name="assignType" class="userSetSelect" style="width: 80%;height: 38px;border-color: #D2D2D2!important;" lay-verify="required" >
                                <#list assignUserTypes?keys as key>
                                <option value="${key}"            >${assignUserTypes[key].title}</option>
                            </#list>
                            <!--<option value="script"            >脚本</option>-->
                            <!--<option value="personScript"      >人员脚本</option>-->
                            <!--<option value="sameNode"          >与已执行节点相同执行人</option>-->
                            <!--<option value="sameNodeDepartment">与已执行节点执行人相同部门</option>-->

                            <!--<option value="orgTypeUserLeader" >部门的上级类型部门的负责人</option>-->
                            <!--<option value="startOrPrev"       >发起人或上一任务执行人的领导或负责人</option>-->
                            <!--<option value="approve"           >当前流程实例审批人</option>-->
                            </select>
                        </td>
                        <td><#--用户来自-->
                            <textarea style="display: none;" name="cmpIds" class="hiddenJson"></textarea>
                            <textarea name="cmpNames" style="display:none;width:73%;min-height: 100px;border-color: #D2D2D2!important;line-height: 20px;vertical-align: bottom;" rows="2" class="textarea" readonly="readonly"></textarea>
                            <a class="windowButton layui-btn layui-btn-sm" style="display:none;" ><span>选择...</span></a>
                        </td>
                        <td><#--抽取用户-->
                            <select name="extractUser" style="width: 80%;height: 38px;border-color: #D2D2D2!important;">
                                <option value="0" >不抽取</option>
                                <option value="1" >抽取</option>
                            </select>
                        </td>
                        <td><#--排序-->
                            <a alt='上移' href='javascript:;' class='link moveup '    onclick="sortTr(this,true)" style="width: 20px;height: 20px;"><i class="iconfont iconlong-arrow-up"></i></a>
                            <a alt='下移' href='javascript:;' class='link movedown '  onclick="sortTr(this,false)" ><i class="iconfont iconlong-arrow-down"></i></a>
                        </td>
                        <td><#--运算关系-->
                            <select name="compType" style="width: 80%;height: 38px;border-color: #D2D2D2!important;">
                                <option value='0' >或</option>
                                <option value='1' >与</option>
                                <option value='2' >排除</option>
                            </select>
                        </td>
                    </tr>
                </#if>
                </tbody>
                </table>
            </div>
            <div style="display: none">
                <#--
                <div id="userSetTypesSelectOpt">
                    <#list userSetTypes?keys as key>
                    <option value="${key}" <#if key=='users'>selected="selected"</#if> >${userSetTypes[key].title}</option>
            </#list>
        </div>
        -->
        <#--JSON-->
        <textarea id="conditionEntity">
						{
						setId:"${setId}",
						procDefId:"${actDefModel.procDefId}",
						nodeId:"${bpmUserCondition.nodeId}",
						conditionId:"${bpmUserCondition.id}",
						conditionType:"${bpmUserCondition.conditionType}",
						sn:"${(bpmUserCondition.sn)?c}",
						groupNo:"${bpmUserCondition.groupNo}",
						formIdentity:"${bpmUserCondition.formIdentity}"
						}
				</textarea>

</div>
</div>
</fieldset>
</div>

<!--todo 三个及以上个 弹窗时启用的-->
<div id="windowUrls" style="display: none"></div>
<script id="scriptStr" type="text/html">
    <div class="layui-form-item" style="border: 1px solid #C0C4CC;position: relative; height: 37px; width: 90%;margin: 4px 0 4px 4px;padding: 5px 0;">
    <span style="display: none;border-right: 1px solid #555;position: absolute;top: -30px;right: -30px;height: 10px;"></span>
        <span style="display: none;border-right: 1px solid #555;position: absolute;top: 0px;right: -30px;height: 15px;"></span>
        <span style="display: none;border-top: 1px solid #555;position: absolute;top: -30px;right: -30px;width: 30px;"></span>
        <span style="display: none;border-top: 1px solid #555;position: absolute;top: 14px;right: -30px;width: 30px;"></span>
        <select style="display: none;position: absolute;top: -20px;right: -50px;" class="compTypeSel">
            <option value="and">且</option>
            <option value="or">或</option>
        </select>
    <input name='RulesCK' style='float: left;margin: 13px 0 0 10px;' type="checkbox">
            <label class="layui-form-label">脚本规则</label>
            <textarea class="script-add-role theJiaoben" style='float: left;display:none;'></textarea>
        <button class="layui-btn layui-btn-xs addDivz" style="margin: 7px 0 0 10px;">脚本</button>
    </div>
</script>
<script id="ruleStr" type="text/html">
        <div class="layui-form-item" style="padding: 5px 0;border: 1px solid #C0C4CC; position:relative;height: 37px; width: 90%;margin: 4px 0 4px 4px">
        <span style="display: none;border-right: 1px solid #555;position: absolute;top: -30px;right: -30px;height: 10px;"></span>
            <span style="display: none;border-right: 1px solid #555;position: absolute;top: 0px;right: -30px;height: 15px;"></span>
            <span style="display: none;border-top: 1px solid #555;position: absolute;top: -30px;right: -30px;width: 30px;"></span>
            <span style="display: none;border-top: 1px solid #555;position: absolute;top: 14px;right: -30px;width: 30px;"></span>
            <select style="display: none;position: absolute;top: -20px;right: -50px;" class="compTypeSel">
                <option value="and">且</option>
                <option value="or">或</option>
            </select>
        <input name='RulesCK' style='float: left;margin: 13px 0 0 10px;' type="checkbox">
                <div style="float: left">
                    <label class="layui-form-label" >普通规则</label>
                    <div class="layui-input-block" style="line-height: 36px;">
                          <select name="city" lay-verify="required" style='vertical-align: middle;height: 38px;border-color: #D2D2D2!important;' class='someRule'>
                                <option value="0">--请选择--</option>
                                <option value="" disabled="disabled">表单变量</option>
                                <option value="startUser"    id='startUser'>发起人ID</option>
                                <option value="businessKey"  id='businessKey'>表单主键</option>
                              <option value="flowRunId"      id='flowRunId'>流程运行ID</option>
        <#if bpmDefVars?? >
                               <option value="" disabled="disabled">自定义变量</option>
        <#list bpmDefVars as var>
                                       <option value= ${var.varKey} id=${var.varDataType}>${var.varName}</option>
    </#list>
    </#if>
                      </select>
                </div>
            </div>
            <div style="margin-top: -6px;display: none" class="holiday" opttype="1">
                <div class="layui-input-block" style="margin-left: 4px; float: left">
                      <select name="city" lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;'>
                                <option value="==" >等于</option>
                                <option value="!=">不等于</option>
                                <option value=">">大于</option>
                                <option value="<">小于</option>
                                <option value=">=">大于等于</option>
                                <option value="<=">小于等于</option>
                          </select>
                </div>
                <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" style="width: 120px;height: 38px;border-color: #D2D2D2!important;float: left">
                <div class="layui-input-block" style='margin-left: 4px; float: left'>
                          <select name="city" lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;' >
                                    <option value="==" >等于</option>
                                    <option value="!=">不等于</option>
                                    <option value=">">大于</option>
                                    <option value="<">小于</option>
                                    <option value=">=">大于等于</option>
                                    <option value="<=">小于等于</option>
                              </select>
                    </div>
                <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" style="width: 120px;height: 38px;border-color: #D2D2D2!important;margin-top: 6px">
            </div>
            <div style="margin-top: -6px;display: none" class="holiday" opttype="3">
                <div class="layui-input-block" style="margin-left: 4px; float: left">
                      <select name="city" class='selectOne' lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;'>
                                <option value="==" >等于</option>
                                <option value="!=">不等于</option>
                                <option value=">">大于</option>
                                <option value="<">小于</option>
                                <option value=">=">大于等于</option>
                                <option value="<=">小于等于</option>
                          </select>
                </div>
                <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" id='oneDate{{ d.nam }}' placeholder='yyyy-MM-dd' style="width: 120px;height: 38px;border-color: #D2D2D2!important;float: left">
                <div class="layui-input-block" style='margin-left: 4px; float: left'>
                          <select name="city" lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;' >
                                    <option value="==" >等于</option>
                                    <option value="!=">不等于</option>
                                    <option value=">">大于</option>
                                    <option value="<">小于</option>
                                    <option value=">=">大于等于</option>
                                    <option value="<=">小于等于</option>
                              </select>
                    </div>
                <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" id='twoDate{{ d.nam }}' placeholder='yyyy-MM-dd' style="width: 120px;height: 38px;border-color: #D2D2D2!important;margin-top: 6px">
            </div>
        <div style="display: none;margin-top: -6px" class="startID" opttype="5">
            <div class="layui-input-block" style="margin-left: 4px; float: left">
                <select name="city" lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;'>
                        <option value="contains()" >包含</option>
                        <option value="noContains()">不包含</option>
                    </select>
            </div>
            <input type="hidden" name="startUserId" float: left">
            <input type="text" name="title" required  readonly="readonly" lay-verify="required" autocomplete="off" class="layui-input" style="width: 120px;height: 38px;border-color: #D2D2D2!important;float: left">
            <button class="layui-btn layui-btn-xs selectUser" style='margin: 15px 0 0 10px;'>选择</button>
        </div>
        <div style="display: none;margin-top: -6px" class= "formID" opttype="2">
            <div class="layui-input-block" style="margin-left: 4px; float: left">
                <select name="city" lay-verify="required" style='height: 38px;border-color: #D2D2D2!important;'>
                        <option value="equals()" >完全等于</option>
                        <option value="!=">不等于</option>
                        <option value="equalsIgnoreCase()">等于（忽略大小写）</option>
                        <option value="contains()">包含</option>
                        <option value="noContains()">不包含</option>
                    </select>
            </div>
            <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" style="width: 120px;height: 38px;border-color: #D2D2D2!important;float: left">
        </div>
    </div>
</script>
<script>
    var ces;
    var assignUseType=0;
    function changeLoad(url){
        $("#ruleDiv").load(url);
    }
    function sortTr(obj,up){
        var thisTr = $(obj).parents("tr");
        if(up){
            var prevTr = $(thisTr).prev();
            if(prevTr){
                thisTr.insertBefore(prevTr);
            }
        } else {
            var nextTr = $(thisTr).next();
            if(nextTr){
                thisTr.insertAfter(nextTr);
            }
        }
    };
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer', 'table', 'element','setter','form','jquery','laytpl','laydate','commons'], function(){
        var layer = layui.layer
            ,table = layui.table
            ,element = layui.element
            ,setter = layui.setter
            ,form=layui.form
            ,$ = layui.jquery
            ,laytpl = layui.laytpl
            ,commons = layui.commons
            ,laydate = layui.laydate;
        var modelId = "${modelId}";
        //全局使用。即所有弹出层都默认采用，但是单个配置skin的优先级更高
        layer.config({
            skin: 'btn-class'
        })
        //添加规则
        var nam = 1;
        function addRuleStr(){
            //渲染模版
            var data = { //数据
                "nam" : nam
            }
            var getTpl = ruleStr.innerHTML
                ,view = document.getElementById('ruleDiv');
            laytpl(getTpl).render(data, function(html){
                view.innerHTML += html;
            });
            laydateGZ();
            nam++;
        };
        //添加规则触发事件
        $('#addRule').click(function () {
            addRuleStr();
            showConnect();
            someRuleChange();
        });
        //监听ruleDiv发生变化
        $(document).on("click",".selectUser",function(){
            // layer.alert('只想简单的提示');
            var body;
            var userSelectorWin;
            var itemName='';
            var itemId='';
            var that = $(this).prev();
            var thatHidden = $(this).prev().prev();
            // parent.
            parent.layer.open({
                type:2
                ,title:'人员选择器'
                ,area:['980px','630px']
                ,btn:["保存","取消","撤销"]
                ,resize:false
                ,content: serverPath.systemPath + setter.sysLinkPath+'dialog/view/sysUserDialog'
                ,success: function(layero, index){
                    body = parent.layer.getChildFrame('body',index);
                    userSelectorWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                    if (that.val()) {
                        userSelectorWin.layui.userList = [];
                        var hiddenDataArr = thatHidden.val().split(",");
                        var theDataArr = that.val().split(",");
                        $.each(hiddenDataArr,function (k,v) {
                            var userListObj={};
                            userListObj.name = theDataArr[k];
                            userListObj.userId = v;
                            userSelectorWin.layui.userList.push(userListObj);
                        })
                    }
                },
                yes:function(index,layero){
                    var theUserList = body.find("input[name=userList]").val();
                    if (theUserList){
                        //用户选择器返回的选择人员数组[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                        $.each(JSON.parse(theUserList),function (index, item) {
                            itemName += item.name + ",";
                            itemId += item.userId + ",";
                        });
                        if (itemName.length > 0) {
                            itemName = itemName.substr(0,itemName.length - 1);
                            itemId = itemId.substr(0,itemId.length - 1);
                        }
                        that.val(itemName);
                        thatHidden.val(itemId);
                    }else{
                        that.val('');
                        thatHidden.val('');
                    }
                    parent.layer.close(index);

                },
                btn3:function(index, layero){
                    userSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            });
        })
        function showConnect() {
            var divlangth = $('#ruleDiv>div').length;
            if (divlangth>1){
                for (var i=0;i<divlangth;i++) {
                    if (i!==0){
                        $('#ruleDiv>div').eq(i).children("span").show();
                        $('#ruleDiv>div').eq(i).children("select").show();
                    }else {
                        $('#ruleDiv>div').children("span").hide();
                        $('#ruleDiv>div').children("select").hide();
                    }
                }
            }else {
                $('#ruleDiv>div').children("span").hide();
                $('#ruleDiv>div').children("select").hide();
            }
        };

        /**
         * 规则设置的判断区间
         * [optType ='1']  等于、不等于、大于、小于、大于等于、小于等于               自定义变量：数字；流程运行ID
         * [optType ='2']  完全等于、不等于、等于（忽略大小写）、包含、不包含          自定义变量：字符串；表单主键
         * [optType ='3']  （时间格式） 等于、不等于、大于、小于、大于等于、小于等于   自定义变量：日期
         * [optType ='4']  等于、不等于、包含、不包含
         * [optType ='5']  包含、不包含                                              发起人ID
         */
        function someRuleChange(){
            $('.someRule').change(function () {
                ruleChange(this);
            })
        };

        //普通规则改变触发事件
        function ruleChange(element) {
            var optionId = $("option:selected",element).attr("id");
            if (optionId == "flowRunId" || optionId == "number") {
                $(element).parent().parent().siblings("[optType ='2']").hide();
                $(element).parent().parent().siblings("[optType ='5']").hide();
                $(element).parent().parent().siblings("[optType ='3']").hide();
                $(element).parent().parent().siblings("[optType ='1']").show();
                // optTypeFunc();
            } else if (optionId == "startUser") {
                $(element).parent().parent().siblings("[optType ='1']").hide();
                $(element).parent().parent().siblings("[optType ='2']").hide();
                $(element).parent().parent().siblings("[optType ='3']").hide();
                $(element).parent().parent().siblings("[optType ='5']").show();
            } else if (optionId == "businessKey" || optionId == "varchar") {
                $(element).parent().parent().siblings("[optType ='1']").hide();
                $(element).parent().parent().siblings("[optType ='5']").hide();
                $(element).parent().parent().siblings("[optType ='3']").hide();
                $(element).parent().parent().siblings("[optType ='2']").show();
            } else if (optionId == "date"){
                $(element).parent().parent().siblings("[optType ='2']").hide();
                $(element).parent().parent().siblings("[optType ='5']").hide();
                $(element).parent().parent().siblings("[optType ='1']").hide();
                $(element).parent().parent().siblings("[optType ='3']").show();
            }else {
                $(element).parent().parent().siblings("[optType ='1']").hide();
                $(element).parent().parent().siblings("[optType ='2']").hide();
                $(element).parent().parent().siblings("[optType ='3']").hide();
                $(element).parent().parent().siblings("[optType ='5']").hide();
            }
        };
        function laydateGZ(){
            laydate.render({
                elem: '#oneDate'+nam, //指定元素
            });
            laydate.render({
                elem: '#twoDate'+nam, //指定元素
            });
        }
        //添加脚本触发事件
        $('#addDivf').click(function () {
            //渲染模版
            var data = { //数据
            }
            var scriptTpl = scriptStr.innerHTML
                ,view = document.getElementById('ruleDiv');
            laytpl(scriptTpl).render(data, function(html){
                view.innerHTML += html;
            });
            showConnect();
            scriptClick();

        });
        //脚本弹出层（人员设置:脚本）
        function scriptClick() {
            parent.layer.open({
                title:'脚本',
                type: 2,
                shade: 0.3,
                btn:["保存","关闭"],
                skin: 'btn-class',
                area: ['900px', '600px'],
                content: serverPath.workflowPath + setter.workflowLinkPath +'bpmNodeUser/view/script?modelId='+modelId,
                // content: $('#windowUrls')
                yes:function (index,layero) {
                    //获取iframe的body元素
                    var body = parent.layer.getChildFrame('body',index);
                    //得到iframe页的窗口对象
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    //执行iframe页的showMsg方法
                    var theDiv = iframeWin.frames[0].document.children[0].getElementsByClassName("editbox")[0].innerText;
                    $(".theJiaoben").html(theDiv);
                    $(".theJiaoben").removeClass("theJiaoben");
                    parent.layer.close(index);
                }
                // });
            });


        };
        //脚本弹出窗（规则设置:脚本规则）
        $(document).on("click",".addDivz",function(){
            $(this).prev().addClass("theJiaoben");
            var data = $(this).prev().text();
            parent.layer.open({
                title:'脚本',
                type: 2,
                shade: 0.3,
                btn:["保存","关闭"],
                skin: 'btn-class',
                area: ['80%', '90%'],
                content:serverPath.workflowPath + setter.workflowLinkPath +'bpmNodeUser/view/script?modelId='+modelId+'&data='+data,
                yes:function (index,layero) {
                    //获取iframe的body元素
                    var body = parent.layer.getChildFrame('body',index);
                    //得到iframe页的窗口对象
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    var theDiv = iframeWin.frames[0].document.children[0].getElementsByClassName("editbox")[0].innerText;
                    $(".theJiaoben").html(theDiv);
                    $(".theJiaoben").removeClass("theJiaoben");
                    parent.layer.close(index);
                }

            });
        })

        //规则删除
        $('#theDelRules').click(function (){
            var cks=$("#ruleDiv input[name=RulesCK]:checked");
            if(cks.length==0){
                layer.confirm('请选择删除的规则！', {
                    btn: "确定"
                    , title: '提示信息'
                    , yes: function () {
                        layer.close(layer.index);
                    }
                });
                return ;
            }
            layer.confirm('确定要删除所选项吗?', {icon: 3, title:'提示'}, function(index){
                //do something
                for(var i=cks.length-1;i>=0;i--) {
                    $(cks[i]).parent().remove();
                }
                layer.close(index);
                showConnect();
            });

        })

        //人员添加
        var html=$("#tbodyUserSet tr").eq(0).html();
        $('#addUser').click(function (){
            $("#tbodyUserSet").last().append("<tr>"+html+"</tr>");
            $("#tbodyUserSet tr").last().find(".textarea").text("");
            $("#tbodyUserSet tr").last().find(".hiddenJson").text("");
        })

        //人员删除
        $('#delUser').click(function (){
            var cks=$("#userTable input[name=nodeUserCk]:checked");
            if(cks.length==0){
                layer.confirm('请选择删除的记录！', {
                    btn: "确定"
                    , title: '提示信息'
                    , yes: function () {
                        layer.close(layer.index);
                    }
                });
                return ;
            }
            for(var i=cks.length-1;i>=0;i--) {
                $(cks[i]).parent().parent().remove();
            }
        })

        //"用户类型"下拉框更改时，文本框内容清除
        $(document).on("change",".userSetSelect",function () {
            $(this).parent().parent().find(".hiddenJson").text("");
            $(this).parent().parent().find(".textarea").text("");
            if ($(this).val()=="startUser"||$(this).val()=="approve"){
                $(this).parent().parent().find(".textarea").hide();
                $(this).parent().parent().find(".windowButton").hide();
            }else {
                $(this).parent().parent().find(".textarea").show();
                $(this).parent().parent().find(".windowButton").show();
            }
        });
        //"用户来自"选择元素的不同弹窗设置
        $(document).off('click','.windowButton').on('click', '.windowButton', function () {
            // $('.windowButton').click(function () {
            var theData = $(this).siblings(".textarea");
            var hiddenData = $(this).siblings(".hiddenJson");
            //获取当前行的选中值
            var val= $(this).parent().parent().find('.userSetSelect').val();
            //弹窗名称
            var windowUrl = '';
            //弹窗路径
            var windowTitle='';
            //弹窗参数（JSON格式）
            var cmpIds  = $(this).siblings(".hiddenJson").html();
            //JSON参数中特殊符号转义处理
            cmpIds = cmpIds.replace("\"", "%22").replace("{", "%7b").replace("}", "%7d");
            //根据获取的id值，判断选择弹窗的路径
            var userSelectorWin;
            var body;
            var itemName='';
            var itemId='';
            switch (val) {
                case 'users':
                    parent.layer.open({
                        type:2
                        ,title:'人员选择器'
                        ,area:['980px','630px']
                        ,btn:["保存","取消","撤销"]
                        ,resize:false
                        ,content: serverPath.systemPath + setter.sysLinkPath+'dialog/view/sysUserDialogWithOrgName'
                        ,success: function(layero, index){
                            body = parent.layer.getChildFrame('body',index);
                            userSelectorWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                            if (theData.text()) {
                                userSelectorWin.layui.userList = [];
                                var hiddenDataArr = hiddenData.text().split(",");
                                var theDataArr = theData.text().split(",");
                                $.each(hiddenDataArr,function (k,v) {
                                    var userListObj={};
                                    var indexLeft = theDataArr[k].indexOf('[');
                                    var indexRight = theDataArr[k].indexOf(']');
                                    userListObj.name = theDataArr[k].substring(0,indexLeft);
                                    userListObj.userId = v;
                                    userListObj.orgName = theDataArr[k].substring(indexLeft+1,indexRight);
                                    userSelectorWin.layui.userList.push(userListObj);
                                })
                            }
                        }
                        ,yes:function(index,layero){
                            var theUserList = body.find("input[name=userList]").val();
                            if (theUserList){
                                //用户选择器返回的选择人员数组[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                                $.each(JSON.parse(theUserList),function (index, item) {
                                    itemName += item.name + "["+item.orgName+"],";
                                    itemId += item.userId + ",";
                                });
                                if (itemName.length > 0) {
                                    itemName = itemName.substr(0,itemName.length - 1);
                                    itemId = itemId.substr(0,itemId.length - 1);
                                };
                            }else{
                                itemName='';
                                itemId='';
                            }
                            theData.html(itemName);
                            hiddenData.html(itemId);
                            parent.layer.close(index);
                        },
                        btn3:function(index, layero){
                            userSelectorWin.cancelData(index);
                            return false //开启该代码可禁止点击该按钮关闭
                        }
                    });
                    break;
                case 'role':
                    parent.layer.open({
                        type: 2
                        , title: '角色选择器'
                        , area: ['980px', '630px']
                        ,btn:["保存","取消","撤销"]
                        , resize: false
                        , content:serverPath.systemPath + setter.sysLinkPath +'dialog/view/sysRoleDialog'
                        ,success: function(layero, index){
                            body = parent.layer.getChildFrame('body',index);
                            userSelectorWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                            // userSelectorWin.layui.userList.push({name:"wc",userId:"ec17d71488dd43f3ac8ea1a01971d7cc"});
                            if (theData.text()) {
                                userSelectorWin.layui.roleList = [];
                                var hiddenDataArr = hiddenData.text().split(",");
                                var theDataArr = theData.text().split(",");
                                $.each(hiddenDataArr,function (k,v) {
                                    var userListObj={};
                                    userListObj.name = theDataArr[k];
                                    userListObj.roleId = v;
                                    userSelectorWin.layui.roleList.push(userListObj);
                                })
                            }
                        }
                        ,yes:function(index,layero){
                            var roleList = body.find("input[name=roleList]").val();
                            if (roleList){
                                $.each(JSON.parse(roleList),function (index, item) {
                                    itemName += item.name + ",";
                                    itemId += item.roleId + ",";
                                });
                                if (itemName.length > 0) {
                                    itemName = itemName.substr(0,itemName.length - 1);
                                    itemId = itemId.substr(0,itemId.length - 1);
                                };
                            }else{
                                itemName='';
                                itemId='';
                            }
                            theData.html(itemName);
                            hiddenData.html(itemId);
                            parent.layer.close(index);
                        },
                        btn3:function(index, layero){
                            userSelectorWin.cancelData(index);
                            return false //开启该代码可禁止点击该按钮关闭
                        }
                    });
                    break;
                case 'org':
                    parent.layer.open({
                        type: 2
                        , title: '组织选择器'
                        , area: ['980px', '630px']
                        ,btn:["保存","取消","撤销"]
                        , resize: false
                        , content: serverPath.systemPath + setter.sysLinkPath+ 'dialog/view/sysOrgDialog'
                        ,success: function(layero, index){
                            body = parent.layer.getChildFrame('body',index);
                            userSelectorWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                            if (theData.text()) {
                                userSelectorWin.layui.orgList = [];
                                var hiddenDataArr = hiddenData.text().split(",");
                                var theDataArr = theData.text().split(",");
                                $.each(hiddenDataArr,function (k,v) {
                                    var userListObj={};
                                    userListObj.name = theDataArr[k];
                                    userListObj.orgId = v;
                                    userSelectorWin.layui.orgList.push(userListObj);
                                })
                            }
                        }
                        ,yes: function(index, layero){
                            var theUserList = body.find("input[name=orgList]").val();
                            if (theUserList){
                                $.each(JSON.parse(theUserList),function (index, item) {
                                    var subStr = item.name.indexOf("<");
                                    if(subStr == '-1'){
                                        itemName += item.name + ",";
                                    }else{
                                        itemName += item.name.substr(0, subStr) + ",";
                                    }
                                    itemId += item.orgId + ",";
                                });
                                if (itemName.length > 0) {
                                    itemName = itemName.substr(0,itemName.length - 1);
                                    itemId = itemId.substr(0,itemId.length - 1);
                                };
                            }
                            theData.html(itemName);
                            hiddenData.html(itemId);
                            parent.layer.close(index);
                        },
                        btn3:function(index, layero){
                            userSelectorWin.cancelData(index);
                            return false //开启该代码可禁止点击该按钮关闭
                        }
                    });
                    break;
                case 'sameNode':
                    windowTitle = '与已执行节点相同执行人选择';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowNodeUser?modelId=${modelId}&&nodeId=${nodeId}&windowName=sameNode';
                    break;
                case 'script':
                    windowTitle = '脚本选择';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowScript?modelId=${modelId}&&nodeId=${nodeId}&windowName=script';
                    break;
                case 'orgTypeUserLeader':
                    windowTitle = '部门的上级类似部门的负责人';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowUpSection?modelId=${modelId}&&nodeId=${nodeId}&windowName=orgTypeUserLeader';
                    break;
                case 'formVar':
                    layer.open({
                        title:'人员表单变量',
                        type: 2,
                        shade: 0.3,
                        area: ['90%', '90%'],
                        content:serverPath.workflowPath + setter.workflowLinkPath +'bpmNodeUser/view/userWindowFormVar?procDefId=${actDefModel.procDefId}&&parentProcDefId=${parentProcDefId}&&cmpIds='+cmpIds
                    });
                    break;
                case 'startOrPrev':
                    windowTitle = '发起人或上一任务执行人的领导或负责人';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowStartOrUpNodeUser?cmpIds='+cmpIds+"&windowName=startOrPrev";
                    break;
                case 'startOrPrevWithOrg':
                    windowTitle = '与发起人或上一任务执行人具有相同组织的人';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowStartOrUpNodeUser?isOrg=true&&cmpIds='+cmpIds+'&windowName=startOrPrevWithOrg';
                    break;
                case 'sameNodeDepartment':
                    windowTitle = '与已执行节点执行人相同部门';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/userWindowNodeUser?modelId=${modelId}&&nodeId=${nodeId}&windowName=sameNodeDepartment';
                    break;
                case 'personScript':
                    windowTitle = '人员脚本';
                    windowUrl = '${ctx}/workflow/bpmNodeUser/view/personScript?modelId=${modelId}&&nodeId=${nodeId}&windowName=personScript';
                    break;
            };
            //弹窗统一格式
            if(windowTitle.length>0&&windowUrl.length>0) {
                $('#windowUrls').load(windowUrl);
                layer.open({
                    title: windowTitle,
                    type: 1,
                    shade: 0.3,
                    area: ['90%', '90%'],
                    // area: ['500px', '380px'],
                    content: $('#windowUrls'),
                    btn:['保存','关闭'],
                    success:function(layero,index){
                    },
                    yes:function (index,layero) {//index 为当前页面索引，layero 为当前页面的DOM，所以可以利用下面的方式获取
                        if ($(".windowName").text()=="personScript") {
                            var theDataText='';
                            var hiddenDataText = '';
                            $.each($(layero).find('table tbody tr'),function (k,v) {
                                if ($(v).find("td").eq(3).find("select[name=paraCt]").val()==1){
                                    theDataText+=$(v).find("td").eq(2).text()+":"+$(v).find("td").eq(3).find("select[name=paraCtType] option:selected").text();
                                    hiddenDataText+=$(v).find("td").eq(3).find("select[name=paraCtType]").val()+',';
                                }else {
                                    theDataText+=$(v).find("td").eq(2).text()+":"+$(v).find("td").eq(3).find("input[name=paraValID]").val();
                                    hiddenDataText+=$(v).find("td").eq(3).find("input[name=paraValID]").val()+',';
                                }
                            });
                            hiddenDataText=hiddenDataText.substring(0,hiddenDataText.length-1);
                            hiddenData.html('retutn '+$(layero).find('input[name=classInsName]').val()+'.'+$(layero).find('input[name=methodName]').val()+'('+hiddenDataText+')');
                            theData.html($(layero).find('input[name=condScriptName]').val()+'参数设置：('+theDataText+')');
                            // 关闭弹窗
                            layer.close(index);
                        }else if ($(".windowName").text()=="sameNodeDepartment"||$(".windowName").text()=="sameNode"){
                            var hiddenJson = '{nodeId:\"'+$("td input:checked").val()+'\"}';
                            var data = $("td input:checked").attr("nodeName");

                            //对前弹窗文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(data);
                            //关闭弹窗
                            layer.close(index);
                            return false;
                        }else if($(".windowName").text()=="startOrPrevWithOrg"||$(".windowName").text()=="startOrPrev"){
                            //获取选中的按钮
                            var type    = $("input[name=type]:checked").val();
                            var userType= $("input[name=userType]:checked").val();
                            var isOrg   = $("input[name=isOrg]").val();
                            var varTypeName    = $("input[name=type]:checked").attr("memo");
                            var varUserTypeName= $("input[name=userType]:checked").attr("memo");

                            var hiddenJson ='{type:\"'+type+'\",userType:\"'+userType+'\"}';
                            var showTxt;
                            if(!isOrg){
                                //执行人
                                showTxt=varUserTypeName +"的"+varTypeName;
                            }else{
                                //执行人的部门
                                showTxt='与'+varUserTypeName +'具有'+varTypeName;;
                            }
                            //对前弹窗的文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(showTxt);
                            //关闭弹窗
                            layer.close(layer.index);
                            return false;
                        }else if ($(".windowName").text()=="orgTypeUserLeader"){
                            //获取选中的按钮
                            var demId = $("input[name=demensionId]:checked").val();
                            var level=$(' select[name=level]').val();
                            var orgSource=$('input:radio[name=orgSource]:checked').val();
                            var isUpQuery = $('input:radio[name=isUpQuery]:checked').val();

                            var orgSourceText = $("input:radio[name=orgSource]:checked").next('span').html();
                            var levelText = $('select[name=level]').find("option:selected").text();
                            var isUpQueryText = $("input:radio[name=isUpQuery]:checked").next('span').html();

                            var hiddenJson ="{\"demId\":\""+demId+"\",\"orgSource\":\""+orgSource+"\",\"level\":\""+level+"\",\"isUpQuery\":"+isUpQuery+"}";
                            var showTxt="类型:"+orgSourceText+";部门类型:"+levelText+";查找策略:"+isUpQueryText;
                            //对前弹窗的文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(showTxt);
                            // 关闭弹窗
                            layer.close(index);
                            return false;
                        }else if($(".windowName").text()=="script"){
                            //获取本弹窗添加的值
                            InitMirror.editor.save();
                            var data = $('#typeScript').val();
                            //对前弹窗文本域赋值
                            theData.html(data);
                            hiddenData.html(data);
                            //关闭弹窗
                            layer.close(index);
                            return false;
                        }
                    }
                });
            }
        });
        //关闭
        var index = parent.layer.getFrameIndex(window.name);
        $(document).on('click', '#close', function () {
            parent.layer.close(index);
        });
        //保存
        window.save = function (closeOpen,callback) {
            var param=eval("("+$("#conditionEntity").val()+")");

            var users=extractNodeUserDatas();
            if(!users){
                layer.alert("没有设置用户!","提示信息");
                return
            }else{
                param.users=JSON.stringify(users);
            }
            assignUseType=param.conditionType;

            var conditionShow = [];
            $("#tbodyUserSet tr").each(function() {
                conditionShow.push($('select[name="assignType"] option:selected',$(this)).text()+":"+$(".textarea", $(this)).val());
            });
            if(conditionShow){
                param.conditionShow=conditionShow.join(",");
            }
            var parentProcDefId = $("input[name='parentProcDefId']").val();
            if(parentProcDefId){
                param.parentProcDefId=parentProcDefId;
            }
            //规则设置
            var condition = [];
            //规则完整性验证
            var isCondition = true;
            $("#ruleDiv .layui-form-item").each(function(index){
                //公共属性：规则关系compType
                var compType=$(this).find(".compTypeSel").val();

                var _rule = $(".someRule",this);
                var obj1 = {};
                var str ;
                if(_rule.val()){
                    var flowvarKey    = _rule.val();
                    //未选择普通规则
                    if(flowvarKey==0){
                        isCondition=false;
                        return ;
                    }
                    var optType ;
                    var conDesc = $("option:selected",_rule).text();
                    var judgeCon1,judgeCon2;
                    var judgeVal1,judgeVal2;
                    $(_rule).parent().parent().nextAll("div").each(function(){
                        var _this = $(this);
                        if(!_this.is(":hidden")) {
                            //todo 融合表单后，动态生成下拉框时修改判断条件
                            if(flowvarKey=="startUser"){
                                optType   = _this.attr("opttype");
                                judgeCon1 = $("select",_this).val();
                                judgeVal1 = $("input[name='title']",_this).val()+"&&"+$("input[name='startUserId']",_this).val();
                                conDesc  += "  "+$("select option:selected",_this).text()+$("input[name='title']",_this).val();
                            }else if(flowvarKey=="businessKey"){
                                optType   = _this.attr("opttype");
                                judgeCon1 = $("select",_this).val();
                                judgeVal1 = $("input",_this).val();
                                conDesc  += "  "+$("select option:selected",_this).text()+$("input",_this).val();
                            }else{
                                optType   = _this.attr("opttype");
                                var strCon1,strCon2;
                                $("select",_this).each(function (index) {
                                    if(index==0) {
                                        judgeCon1 = $(this).val();
                                        strCon1   = $("option:selected",this).text();
                                        return ;
                                    }
                                    judgeCon2=$(this).val();
                                    strCon2   = $("option:selected",this).text();
                                });
                                $("input",_this).each(function (index) {
                                    if(index==0) {
                                        judgeVal1 = $(this).val();
                                        conDesc  += ("  "+strCon1+"  "+$(this).val());
                                        return ;
                                    }
                                    judgeVal2=$(this).val();
                                    conDesc  += ("  "+strCon2+"  "+$(this).val());
                                })

                            }
                        }
                    });
                    obj1.optType=optType;
                    obj1.flowvarKey=flowvarKey;
                    obj1.judgeCon1=judgeCon1;
                    obj1.judgeVal1=judgeVal1;
                    if(judgeCon2!=null) {
                        obj1.judgeCon2 = judgeCon2;
                        obj1.judgeVal2 = judgeVal2;
                    }
                    obj1.conDesc=conDesc;
                    obj1.ruleType=1;
                    obj1.compType=compType;

                }else{
                    obj1.script=$(".script-add-role",this).val();
                    obj1.conDesc="脚本";
                    obj1.ruleType="2";
                    obj1.compType=compType;
                }
                condition.push(obj1);
            });
            //规则完整性验证
            if(!isCondition) {
                layer.msg("请完整填写普通规则！",{icon:0,time:1000});
                return false;
            }
            param.condition=JSON.stringify(condition);
            param.nodeId    = "${nodeId}";
            param.procDefId = "${actDefModel.procDefId}";
            $.ajax({
                url:serverPath.workflowPath+setter.workflowLinkPath+"bpmUserCondition/save"
                ,method:'post'
                ,data:param
                ,dataType:'json'
                ,success:function (res) {
                    if(commons._filterRecord(res)) {
                        parent.layer.msg(res.msg, {icon: 6, time: 1000},function () {
                            if (callback){
                                callback();//函数的最后
                            }
                            if (closeOpen){
                                closeOpen();//关闭弹窗
                            }
                        })
                    }else {
                        parent.layer.msg(res.msg, {icon: 5, time: 1000})
                    }
                }
            })

            // //关闭弹窗
            // parent.layer.close(index);
            // return false;
        };

        // 获取用户设置
        function extractNodeUserDatas(){
            var users = [];
            // var users;
            $("#tbodyUserSet tr").each(function(index){
                var tr = $(this);
                var nodeId      =   $("input[name='nodeId']").val();
                var nodeUserId  =   $("input[name='modelId']").val();
                var assignType  =   $('select[name="assignType"]',$(this)).val();
                var cmpIds      =   $(".hiddenJson",$(this)).val();
                var cmpNames    =   $(".textarea",$(this)).val();
                var extractUser =   $('select[name="extractUser"]',$(this)).val();
                var compType    =   $('select[name="compType"]',$(this)).val();

                var user={
                    nodeUserId:nodeUserId,
                    assignType:assignType,
                    assignUseType:assignUseType,
                    nodeId:nodeId,
                    cmpIds:cmpIds,
                    cmpNames:cmpNames,
                    compType:compType,
                    extractUser:extractUser
                };
                users.push(user);
            });
            if(users.length==0){
                return false;
            }
            // return users;
            return users;
        };
        //预览
        $("#userLook").click(function () {
            var cksDataHidden = '';
            var cksDataShow = '';

            var mockParamArr = new Array();

            var cksp=$("#userTable input[name=nodeUserCk]:checked").parent().parent();
            $.each(cksp,function (index,element) {
                cksDataHidden += $(element).find(".hiddenJson").text()+",";
                cksDataShow += $(element).find(".textarea").text()+",";
                cksDataHidden=cksDataHidden.replace("\"", "%22").replace("{", "%7b").replace("}", "%7d");
                cksDataShow=cksDataShow.replace("\"", "%22").replace("{", "%7b").replace("}", "%7d").replace("[", "").replace("]", "");
                // temp.replaceAll("\\[", "").replaceAll("\\]", "");
                var mockParams = {};
                mockParams.nodeUserCk = 'true';
                mockParams.nodeUserId = $(element).find("input[name=nodeUserId]").val();
                mockParams.assignType = $(element).find("select[name=assignType]").val();
                mockParams.assignUseType = "0";
                mockParams.cmpIds = $(element).find("textarea[name=cmpIds]").text();
                mockParams.cmpNames = $(element).find("textarea[name=cmpNames]").text();
                mockParams.compType = $(element).find("select[name=compType]").val();
                mockParamArr.push(mockParams);
            });
            if (cksDataHidden.length > 0) {
                cksDataHidden = cksDataHidden.substr(0,cksDataHidden.length - 1);
            }
            if (cksDataShow.length > 0) {
                cksDataShow = cksDataShow.substr(0,cksDataShow.length - 1);
            }
            var show = 0;
            if (mockParamArr.length>0){
                for(var q =0;q<mockParamArr.length;q++){
                        /**
                         * 不支持预览的用户类型：
                         *   1、与已执行节点相同执行人
                         *   2、与已执行节点执行人相同部门
                         *   3、脚本
                         *   4、人员脚本
                         */
                        if (mockParamArr[q].assignType=='sameNode' || mockParamArr[q].assignType=='sameNodeDepartment' || mockParamArr[q].assignType=='script' || mockParamArr[q].assignType=='personScript') {
                            layer.msg("该用户类型不支持预览",{icon:0});
                            return false;
                        }
                    if (mockParamArr[q].assignType!=='startUser') {

                        if (mockParamArr[q].cmpIds=='') {
                            layer.msg("请输入有效参数!",{icon:0});
                            return false;
                        }
                        if (mockParamArr[q].assignType=='startOrPrevWithOrg'||mockParamArr[q].assignType=='startUser') {
                            show = 1;
                        }
                    }else {
                        if (mockParamArr[q].assignType=='startOrPrevWithOrg'||mockParamArr[q].assignType=='startUser') {
                            show = 1;
                        }
                    }

                }
            }else {
                layer.msg("请选择有效参数!",{icon:0});
                return false;
            }

            //转换为一个 JSON字符串
            ces = JSON.stringify(mockParamArr);
            var windowUrl ='${ctx}/workflow/bpmNodeUser/view/userLook?modelId='+modelId+'&cksDataHidden='+cksDataHidden+'&cksDataShow='+cksDataShow;

            $('#windowUrls').load(windowUrl,{},function(response,status,xhr){
                layer.open({
                    title:'预览',
                    type: 1,
                    shade: 0.3,
                    area: ['80%', '90%'],
                    btn : [ "预览", "关闭" ],
                    // content:'#/workflow/bpmNodeUser/view/userLook?modelId='+modelId+'&cksDataHidden='+cksDataHidden+'&cksDataShow='+cksDataShow,
                    content: $('#windowUrls'),
                    success:function (layero,index) {
                        $(".showIs").hide();
                        if (show == 1){
                            $(".showIs").show();
                        }
                    },
                    yes:function (index,layero) {
                        if (show==1&&$(".thatHidden").val()==""){
                            layer.msg("请输入有效参数!",{icon:0});
                            return false;
                        }
                        //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
                        var layid = location.hash.replace(/^#test1=/, '');
                        element.tabChange('test1', "result"); //假设当前地址为：http://a.com#test1=222，那么选项卡会自动切换到“发送消息”这一项
                        var attr = ces;
                        $.ajax({
                            type: 'POST',
                            url: "${ctx}/workflow/bpmNodeUser/preview",
                            data: {   startUserId:$(".thatHidden").val(),
                                modelId:modelId,
                                nodeUser:attr
                            },
                            success: function (res) {
                                var a = res.data;
                                var ces = "";
                                for(var i=0;i<a.length;i++){
                                    ces += a[i].fullName+"["+a[i].account+"]"+" ";
                                }
                                $("#resultView").text(ces);
                            },
                            dataType: 'json'});

                    }
                });
            });

        });


        //规则回显（必须在ruleStr、scriptStr的下面）
        var conditionStr = '${bpmUserCondition.condition}';
        if(conditionStr){
            var ruleArr = JSON.parse(conditionStr);
            for(var i=0;i<ruleArr.length;i++) {
                var _json = ruleArr[i];
                if (_json.script) {
                    //脚本规则
                    $('#ruleDiv').append(scriptStr);
                    showConnect();
                    $('#ruleDiv .script-add-role').each(function () {
                        if ($(this).text()) {
                            $(this).text(_json.script);
                        }
                        $(this).siblings(".compTypeSel").val(_json.compType);
                    });
                } else {
                    //普通规则
                    addRuleStr();
                    $('#ruleDiv .someRule').each(function () {
                        var _this = $(this);
                        if (_this.val() == 0) {
                            _this.val(_json.flowvarKey);
                            someRuleChange();
                            ruleChange(this);
                            showConnect();
                            _this.parents(".layui-form-item").find(".compTypeSel").val(_json.compType);
                            $(_this).parent().parent().nextAll("div").each(function () {
                                var _element = $(this);
                                if (!_element.is(":hidden")) {
                                    $("select", _element).each(function (index) {
                                        if (index == 0) {
                                            $(this).val(_json.judgeCon1);
                                            return;
                                        }
                                        $(this).val(_json.judgeCon2);
                                    });
                                    $("input", _element).each(function (index) {
                                        //发起人
                                        if (_json.flowvarKey == "startUser") {
                                            var _user = (_json.judgeVal1).split("&&");
                                            $("input[name='title']", _element).val(_user[0]);
                                            $("input[name='startUserId']", _element).val(_user[1]);
                                            return;
                                        }
                                        //其他
                                        if (index == 0) {
                                            $(this).val(_json.judgeVal1);
                                            return;
                                        }
                                        $(this).val(_json.judgeVal2);
                                    })
                                }
                            });
                        }
                    });
                }
            }
        }
    });
</script>
</body>
</html>

